package com.enterprise.projectManager.rope;

import com.enterprise.projectManager.model.Contract;

import com.enterprise.projectManager.model.PayProgress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.sql.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;


import java.util.List;
import java.util.Optional;

public interface ContractRope extends JpaRepository<Contract,String> {
    Optional<Contract> findByContractName (String contractName) ;
    List<Contract> findByContractState (String contractState) ;
    Optional<Contract> findByContractNature (String contractNature) ;
    @Query("SELECT DISTINCT c.contractFirstcompany FROM Contract c WHERE c.contractFirstcompany IS NOT NULL")
    List<String> findAllDistinctFirstCompany();
    @Query("SELECT DISTINCT c.contractSecondcompany FROM Contract c WHERE c.contractSecondcompany IS NOT NULL")
    List<String> findAllDistinctSecondCompany();

//    @Query("SELECT c FROM Contract c where (contract_name = 1)")
//    List<Object[]> findEntitiesFromBothTables(String contractName,String contractState,String contractNature);

@Query("SELECT c from Contract c where " +
        "(:contractId is null or c.contractId = :contractId)"+
        "and (:contractName is null or c.contractName LIKE %:contractName%)"+
        "and (:contractNature is null or c.contractNature  LIKE %:contractNature%)"+
        "and (:contractState is null or c.contractState LIKE %:contractState% )"
)
    List<Contract> filterContract(@Param(value = "contractId") String contractId,
                                    @Param(value = "contractName") String contractName,
                                    @Param(value = "contractNature") String contractNature,
                                    @Param(value = "contractState") String contractState
    );

}
